<#import "/spring.ftl" as spring />
<html>
<head>

	<script>
		function editInspection(code, firstName, lastName, otherPhone) {
			document.getElementById("inspectionCode").value = code;
			document.getElementById("firstName").value = firstName;
			document.getElementById("lastName").value = lastName;
			document.getElementById("otherPhone").value = otherPhone;
			document.editInspectionForm.submit();
		}
		
	</script>					
</head>
<body>

<div id="content">

	<h1>INSPECTOR CENTRAL</h1>
	
	<p>Your Personal Action and Inspection Snapshot...</p>
	
	<!-- MY INSPECTIONS -->
	<div class="databoxWrapper">
		<div class="databox">
			<h1>MY INSPECTIONS</h1>
	
			<div class="databoxSubLinks">
				<a href="<@spring.url "/inspector/editInspection.html" />">New Inspection</a>
			</div>
			
			<h2>UPCOMING</h2>
			
			<table class="databoxStandardTable">
			<#if futureInspections??>
				<#list futureInspections?sort_by('inspectionTime') as inspection>
					<#if (inspection.inspectionStatus != "QUICK_BOOK")>
						<#assign isCancelled = inspection.inspectionStatus == "CANCELLED" />
						
						<tr>
							<td <#if isCancelled>class="databoxCancelledText"</#if>>${inspection.inspectionTime?string("MMM dd, h:mma")}</td>
							<td <#if isCancelled>class="databoxCancelledText"</#if>>${inspection.inspector.name}</td>
							<td <#if isCancelled>class="databoxCancelledText"</#if>>${(inspection.property.location.street1)!}, ${(inspection.property.location.city)!}, ${(inspection.property.location.state)!} ${(inspection.property.location.zipCode)!}</td>
							<td class="databoxButtonsCell">
								<#if inspection.paymentTransactionId??>
						 			<a href="<@spring.url "/inspector/inspectionTransaction.html?id=${inspection.id}" />">(payment details)</a>
								</#if>
								<a href="<@spring.url "/inspector/inspection.html?id=${inspection.id}" />" class="databoxButton">VIEW</a>
								<a href="<@spring.url "/inspector/editInspection.html?id=${inspection.id}" />" class="databoxButton">EDIT</a>
							</td>
						</tr>
					</#if>
				</#list>
			</#if>
			</table>
						
			<hr class="databoxDividerHorz" />
						
			<h2>NEEDS ATTENTION</h2>
			
			<table class="databoxStandardTable">
			<#if futureInspections??>
				<#list futureInspections?sort_by('inspectionTime') as inspection>
					<#if (inspection.inspectionStatus == "QUICK_BOOK")>
						<tr>
							<td>${inspection.inspectionTime?string("MMM dd, h:mma")}</td>
							<td>${inspection.inspector.name}</td>
							<td>${inspection.homeBuyer.name.first!} ${inspection.homeBuyer.name.last!}  (${inspection.homeBuyer.email})</td>
							<td class="databoxButtonsCell">
								<a href="<@spring.url "/inspector/inspection.html?id=${inspection.id}" />" class="databoxButton">VIEW</a>
								<a href="<@spring.url "/inspector/editInspection.html?id=${inspection.id}" />" class="databoxButton">EDIT</a>
							</td>
						</tr>
					</#if>
				</#list>
			</#if>
			</table>
						
			<hr class="databoxDividerHorz" />
						
			<h2>PAST INSPECTIONS</h2>
			
			<p class="databoxSubtext">NOTE: CMP=Complete, CLD=Cancelled, EXP=Auto-expired , SCD=Scheduled</p>
			
			<table class="databoxStandardTable">
			<#if pastInspections??>
				<#list pastInspections?sort_by('inspectionTime')?reverse as inspection>
					<tr>
						<td>${inspection.inspectionTime?string("MMM dd, h:mma")} 
							<span class="databoxSubtext">
							<#if inspection.inspectionStatus == "COMPLETED">
								(CMP)
							<#elseif inspection.inspectionStatus == "CANCELLED">
								(CLD)
							<#elseif inspection.inspectionStatus == "AUTO_EXPIRED">
								(EXP)
							<#elseif inspection.inspectionStatus == "SCHEDULED">
								(SCD)
							</#if>
							</span>	
						<td>${inspection.inspector.name}</td>
						<td>${(inspection.property.location.street1)!}, ${(inspection.property.location.city)!}, ${(inspection.property.location.state)!} ${(inspection.property.location.zipCode)!}</td>
						<td class="databoxButtonsCell"><a href="<@spring.url "/inspector/inspection.html?id=${inspection.id}" />" class="databoxButton">VIEW</a></td>
					</tr>
				</#list>
			</#if>
			</table>
							
		</div>					
	</div>
	<!-- /MY INSPECTIONS -->

	<p />
	
	<!-- MY ACTION MENU -->
	<div class="databoxWrapper">
		<div class="databox">
			<h1>MY ACTION MENU</h1>
			<table class="databoxDividerTable">
				<tr>
					<td class="databoxDividerCell">
						<table>
							<tr><td class="databoxLinkTxt"><a href="<@spring.url "/inspector/priceAdjusters.html" />">Change Inspection Pricing Plan</a></td></tr>
							<tr><td class="databoxLinkTxt"><a href="<@spring.url "/inspector/fee/optionalServices.html" />">Add or Change Additional Services</a></td></tr>
							<tr><td class="databoxLinkTxt"><a href="<@spring.url "/inspector/editMilesServed.html?id=${inspectorCompany.id}" />">Change Max Miles Served</a></td></tr>
							<tr><td class="databoxLinkTxt"><a href="<@spring.url "/inspector/referringRealtors.html" />">View or change preferred partner Real Estate Agent partners</a></td></tr>
						</table>
					</td>
					<td class="databoxDivider"></td>
					<td class="databoxDividerCell">
						<table>
							<tr><td class="databoxLinkTxt"><a href="<@spring.url "/inspectors/${inspectorCompany.shortName}/schedule1.html" />" target="_new">View your custom site as home buyers see it</a></td></tr>
							<#------ Amazon Payment acceptance link
							<#if (!inspectorCompany.recipientToken??) >
								<tr>
									<td class="databoxLinkTxt">
										<a href="<@spring.url "/inspector/initiateRecipientSetup.html" />">Activate Amazon Payment</a><br/>
										<i style="font-size: 9px;">With this account, you can accept payments for inspections through amazon.com</i><img src="../images/logo-amazon.gif" align="right" />
									</td>
								</tr>
							</#if>
							---------->
						</table>
					</td>
				</tr>
			</table>
		</div>					
	</div>
	<!-- MY ACTION MENU -->

	<p />

	<!-- MY COMPANY -->
	<div class="databoxWrapper">
		<div class="databox">
			<h1>MY COMPANY</h1>
			<h2>${inspectorCompany.name?upper_case}</h2>
			<table class="databoxStandardTable">
				<tr>
					<td>${inspectorCompany.address.street1}, ${inspectorCompany.address.city}, ${inspectorCompany.address.state} ${inspectorCompany.address.zipCode}</td>
					<td class="databoxButtonsCell">
					<a href="<@spring.url "/inspector/editInspectorCompany.html?id=${inspectorCompany.id}" />" class="databoxButton">EDIT</a>
					<a href="#" class="databoxButton">WEBSITE</a>
				</tr>
			</table>
		</div>					
	</div>
	<!-- /MY COMPANY -->
	
	<p />
	
	<#-- Add the inspectors and schedulers together, then 
	     separate into two columns -->
	<#assign employees = inspectorCompany.inspectors />
	<#if inspectorCompany.schedulers??>
		<#assign employees = employees + inspectorCompany.schedulers />
	</#if>
	
	<#if employees?size gt 1>
		<#assign half = (employees?size/2) />
		<#-- hack to round up (later versions of freemarker support rounding-->
		<#if (half != half?int)><#assign half = (half + 0.5) /></#if>
		<#assign column1 = employees[0..half-1] />
		<#assign column2 = employees[half..] />
	<#else>
		<#assign column1 = employees />
	</#if>
	
	<!-- MY STAFF -->	
	<div class="databoxWrapper">
		<div class="databox">
			<h1>MY STAFF</h1>
			<table class="databoxDividerTable">
				<tr>
					<td class="databoxDividerCell">
						<table class="databoxInnerTable">
						<#list column1 as employee>
							<#assign isScheduler = (inspectorCompany.schedulers?seq_contains(employee)) />
							<tr>
								<td>${employee.name} <#if isScheduler>(*)</#if></td>
								<td class="databoxButtonsCell">
								<#if isScheduler>
									<a href="<@spring.url "/inspector/editSchedulerProfile.html?id=${employee.id}" />" class="databoxButton">EDIT</a>
								<#else>
									<a href="<@spring.url "/inspector/editInspectorProfile.html?id=${employee.id}" />" class="databoxButton">EDIT</a>
									<a href="<@spring.url "/inspector/scheduleRule/viewScheduleRules.html?inspectorId=${employee.id}" />" class="databoxButton">SCHEDULE</a>
								</#if>
								</td>
							</tr>
						</#list>
						</table>
					</td>
					<td class="databoxDivider"> </td>
					<td class="databoxDividerCell">
						<#if column2??>
							<table class="databoxInnerTable">
							<#list column2 as employee>
								<#assign isScheduler = (inspectorCompany.schedulers?seq_contains(employee)) />
								<tr>
									<td>${employee.name} <#if isScheduler>(*)</#if></td>
									<td class="databoxButtonsCell">
									<#if isScheduler>
										<a href="<@spring.url "/inspector/editSchedulerProfile.html?id=${employee.id}" />" class="databoxButton">EDIT</a>
									<#else>
										<a href="<@spring.url "/inspector/editInspectorProfile.html?id=${employee.id}" />" class="databoxButton">EDIT</a>
										<a href="<@spring.url "/inspector/scheduleRule/viewScheduleRules.html?inspectorId=${employee.id}" />" class="databoxButton">SCHEDULE</a>
									</#if>
									</td>
								</tr>
							</#list>
							</table>
						</#if>
					</td>
				</tr>
			</table>
			
			<div class="databoxSubLinks">
				<a href="<@spring.url "/inspector/addInspector.html" />">Add Inspector</a>
				<a href="<@spring.url "/inspector/addScheduler.html"/>">Add Scheduler</a>
				(*) Scheduler
			</div>

		</div>					
	</div>
	<!-- /MY STAFF -->

	<form name="editInspectionForm" action="<@spring.url "/inspectors/${inspectorCompany.name}/editIncompleteInspection.html"/>" method="POST">
		<input type="hidden" name="inspectionCode" id="inspectionCode" value="" />
		<input type="hidden" name="homeBuyer.name.first" id="firstName" value="" />
		<input type="hidden" name="homeBuyer.name.last" id="lastName" value="" />
		<input type="hidden" name="homeBuyer.otherPhone" id="otherPhone" value="" />
	</form>

</div>

</body>
</html>
